#ifndef FND_RESOURCE_MANAGER_HPP_
#define FND_RESOURCE_MANAGER_HPP_
#include <string>
#include <map>
#include <stdexcept>
namespace FndGame2D {
    template<typename ValueType> 
    void release_resource(ValueType& v) {
    }
    template<typename KeyType = std::string, 
             typename ValueType = std::string>
    class Manager {
    private:
        typedef std::map<KeyType, ValueType> ManagerMap ;
        ManagerMap m_values ;
    public:
        typedef KeyType key_type ;
        typedef ValueType value_type ;
        bool add_value(const KeyType& key, ValueType v) {
            if(has_value(key)) {
                pantheios::log_DEBUG("key has exist\n") ;
                return	false ;
            }
            m_values.insert(std::make_pair(key, v)) ;
            return true ;
        }

        const ValueType& get_value(const KeyType& key) const {
            if(!has_value(key))
                throw std::range_error("does not has a value") ;
            return m_values.find(key)->second ;
        }

        bool has_value(const KeyType& key) const {
            if(m_values.find(key) != m_values.end())
                return true ;
            return false ;
        }
        bool remove_value(const KeyType& key) {
            if(has_value(key)) {
                ValueType& v = m_values[key] ;
                release_resource(v) ;
                m_values.erase(key) ;
                return true ;
            } else {
                pantheios::log_DEBUG("resource does not exist\n") ;
                return false ;
            }
        }
        ~Manager() {
            typename ManagerMap::iterator it ;
            for(it = m_values.begin() ; it != m_values.end() ; ++it) {
                release_resource((*it).second) ;
            }
        }
    } ;
}

#endif
